const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
    mode: "development",
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: './js/bundle-[hash].js'
    },
    plugins: [
        new HtmlWebpackPlugin({  // Also generate a test.html
            path: path.resolve(__dirname, 'build'),
            filename: 'index.html',
            template: 'tpl/index.html',
            // minify: {   //压缩 去掉所有空格，测试环境不使用
            //     collapseWhitespace: true
            // },
        }),
        new CopyWebpackPlugin([
            {
                from: __dirname + "/tpl/css",
                to: __dirname + "/build/css"
            },
            {
                from: __dirname + "/tpl/fonts",
                to: __dirname + "/build/fonts"
            },
            {
                from: __dirname + "/tpl/js",
                to: __dirname + "/build/js"
            },
            {
                from: __dirname + "/checklist.json",
                to: __dirname + "/build"
            },
            {
                from: __dirname + "/tpl/img",
                to: __dirname + "/build/img"
            }
        ]),
        new CleanWebpackPlugin()
    ]
};